package design_patterns

import (
	"fmt"
	"testing"
)

type ShareStrategy interface {
	Share()
}

type ShareWeibo struct{}

func (s ShareWeibo) Share() {
	fmt.Println("分享到微博")
}

type ShareWechat struct{}

func (s ShareWechat) Share() {
	fmt.Println("分享到微信")
}

type ShareQQ struct{}

func (s ShareQQ) Share() {
	fmt.Println("分享到QQ")
}

type StrategyContext struct {
	ShareInstance ShareStrategy
	StrategyType  string
}

func NewStrategeContext(s ShareStrategy, t string) StrategyContext {
	return StrategyContext{s, t}
}

func (sc StrategyContext) IsMe(t string) bool {
	return sc.StrategyType == t
}

// test case

var stategies []StrategyContext

func init() {
	stategies = append(stategies, NewStrategeContext(ShareWeibo{}, "weibo"))
	stategies = append(stategies, NewStrategeContext(ShareWechat{}, "wechat"))
	stategies = append(stategies, NewStrategeContext(ShareQQ{}, "qq"))

}

func TestAdapter(t *testing.T) {
	typeStr := "weibo"
	for _, c := range stategies {
		if c.IsMe(typeStr) {
			c.ShareInstance.Share()
		}
	}
}
